package com.jvyou.house.controller;

import com.jvyou.common.core.controller.BaseController;
import com.jvyou.common.core.domain.AjaxResult;
import com.jvyou.common.core.page.TableDataInfo;
import com.jvyou.house.domain.House;
import com.jvyou.house.domain.HouseCollect;
import com.jvyou.house.service.IHouseCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 橘柚
 * @since 2024/9/17 10:37
 */
@RestController
@RequestMapping("/house/collect")
public class HouseCollectController extends BaseController {

    @Autowired
    private IHouseCollectService houseCollectService;

    @GetMapping("/my/{id}")
    public TableDataInfo myCollect(@PathVariable Long id) {
        List<House> houses = houseCollectService.myCollect(id);
        return getDataTable(houses);
    }

    @RequestMapping("/list")
    public TableDataInfo list(HouseCollect houseCollect) {
        startPage();
        List<HouseCollect> houseCollects = houseCollectService.selectHouseCollectList(houseCollect);
        return getDataTable(houseCollects);
    }

    @PostMapping()
    public AjaxResult save(@RequestBody HouseCollect houseCollect) {
        return toAjax(houseCollectService.insertHouseCollect(houseCollect));
    }

    @DeleteMapping("/cancel")
    public AjaxResult cancel(@RequestBody HouseCollect houseCollect) {
        return toAjax(houseCollectService.deleteHouseCollect(houseCollect));
    }
}
